package cz.semjob.learning.learner;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import weka.classifiers.Classifier;
import weka.classifiers.trees.J48;
import weka.core.Instances;
import cz.semjob.learning.classifier.LearningException;

@Component
public class J48DataSetLearner implements IDataSetLearner {

	private static Logger logger = Logger.getLogger(J48DataSetLearner.class);

	public String getInfo() {
		return "J48";
	}

	public Classifier buildClassifier(Instances instances)
			throws LearningException {
		// RandomForest classifier = new RandomForest();

		J48 classifier = new J48();
		classifier.setUnpruned(true);
		// classifier.setReducedErrorPruning(true);
		classifier.setBinarySplits(false);
		// classifier.setNumFolds(10);

		try {
			classifier.buildClassifier(instances);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
			throw new LearningException(e);
		}
		return classifier;
	}
}
